package com.eastfair.imaster.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.boot.controller.SuperController;
import com.eastfair.core.base.R;
import com.eastfair.echo.core.EchoService;
import com.eastfair.imaster.dto.VisitorRegisterStateDTO;
import com.eastfair.imaster.dto.VisitorRegisterStatePageQuery;
import com.eastfair.imaster.dto.VisitorRegisterStateSaveDTO;
import com.eastfair.imaster.dto.VisitorRegisterStateUpdateDTO;
import com.eastfair.imaster.entity.VisitorRegisterState;
import com.eastfair.imaster.service.VisitorRegisterStateService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * <p>
 * 前端控制器
 *
 * </p>
 *
 * @author zjn
 * @date 2021-08-18
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/visitorRegisterState")
@Api(value = "VisitorRegisterState", tags = "")
public class VisitorRegisterStateController extends SuperController<VisitorRegisterStateService, Long, VisitorRegisterState, VisitorRegisterStatePageQuery, VisitorRegisterStateSaveDTO, VisitorRegisterStateUpdateDTO> {

    @Autowired
    private EchoService echoService;
    @Autowired
    private VisitorRegisterStateService visitorRegisterStateService;

    @Override
    public void handlerResult(IPage<VisitorRegisterState> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }

    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list) {
        List<VisitorRegisterState> visitorRegisterStateList = list.stream().map((map) -> {
            VisitorRegisterState visitorRegisterState = VisitorRegisterState.builder().build();
            //TODO 请在这里完成转换
            return visitorRegisterState;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(visitorRegisterStateList));
    }

    /**
     * 观众审核
     *
     * @param visitorRegisterStateDTO 观众审核信息
     * @return
     */
    @PostMapping("/audit")
    public R audit(@RequestBody @Validated({VisitorRegisterStateDTO.VerifyUpdateAuditState.class}) VisitorRegisterStateDTO visitorRegisterStateDTO) {
        return R.success(visitorRegisterStateService.updateAuditState(visitorRegisterStateDTO));
    }

}
